﻿@{
    ViewBag.Title = "Recharge";
}
@section scripts
{
    <script src="@Url.Content("~/Scripts/shared/share.js")" type="text/javascript"></script> 
    <script src="@Url.Content("~/Scripts/shared/shown.js")" type="text/javascript"></script>
}
<form id="form1">

            @Html.Partial("~/Views/Modular/Toolbars.cshtml")
            <table style="width:660px;">
                <tr>
                    <td bgcolor="#D7FFFF"><span id="titles">服务商充值：</span></td>
                </tr>
            </table>

            <table style="width:660px;">
                <tr>
                    <td width ="100px" align="right">服务商编码： </td>
                    <td width ="200px">
                        <input id="FNumber" class="mini-buttonedit"style="width:200px; top: 0px; left: 0px;" 
                            onbuttonclick="onButtonEdit" name="FNumber" onvaluechanged ="GetClassID" textName="b" align="left"/>
                     </td>
                    <td width ="80px" align="right">服务商名称：</td>
                    <td width ="200px">
                       <input name="FName" class="mini-textbox" style="width:200px;" readonly="readonly"/></td>
                </tr>
                <tr>
                    <td align="right"><span id="payAmount">充值金额：</span></td>
                    <td >
                        <input name="FAmount" class="mini-spinner" value="0" minValue="-1000000" maxValue="1000000"
                        changeOnMousewheel ="false" showbutton="false" style="width:200px;"/>
                    </td>
                    <td align="right"><span id="payPoint">赠送金额：</span></td>
                    <td >
                        <input name="FSetAmount" class="mini-spinner" value="0" minValue="-1000000" maxValue="1000000" 
                        changeOnMousewheel ="false" showbutton="false" style="width:200px;" />

                    </td>
                    <td align="center">                    
                    </td>
                </tr>
                <tr>
                    <td align="right">付款方式：</td>                        
                    <td>
                        @Html.Partial("~/Views/Modular/LookupPayInfo.cshtml")
                    </td>
                    <td align="right">摘要：
                    </td>
                    <td>
                          <input name="FRemark" class="mini-textbox" style="width:200px;"  maxlength="100" />
                    </td>
                    <tr>
                    <td align="right"></td>
                    <td c>
                    </td>
                    <td></td>
                </tr>
            </table>

        <table style="width:660px;">
            <tr>
                <td bgcolor="#D7FFFF">服务商信息：</td>
            </tr>
        </table>
        <table  style="width:660px;">
                <tr>
                    <td width ="100px" align="right">
                        当前余额：</td>
                    <td width ="200px">
                         <input name="FCurrentAmount" class="mini-spinner" minValue="0" maxValue="99999999" 
                            changeOnMousewheel ="false" showbutton="false" increment ="0" showbutton="false" enabled="false" style="width:200px;" required="true"/>
                   </td>
                    <td width="80px"  align="right">
                        当前积分：</td>
                    <td >
                        <input name="FPoint" class="mini-spinner" minValue="0" maxValue="99999999" 
                            changeOnMousewheel ="false" showbutton="false" increment ="0" showbutton="false" enabled="false" style="width:200px;" required="true"/>
                    </td>
                </tr>
                <tr>
                    <td align="right">
                        </td>
                    <td >
                    </td>
                    <td align="right"></td>
                    <td >
                    </td>
                </tr>

        </table>
           
    <input name="FItemID" class="mini-hidden" />
    <input name="Type" value="@ViewBag.Type" class="mini-hidden" />
    <input name="BillNo" value="@ViewBag.BillNo" class="mini-hidden" />
    <input name="BillID" value="@ViewBag.BillID" class="mini-hidden" />
    </form>
<script>

    function SetInfoData(data) {
        mini.getbyName("FNumber").setValue(data.FItemID);
        mini.getbyName("FNumber").setText(data.FNumber);
        mini.getbyName("FName").setValue(data.FName);
        GetClassID();
        mini.getbyName("FName").setEnabled(false);
        mini.getbyName("FNumber").setEnabled(false);
    }
        function GetQueryString(name) {
            var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
            var r = window.location.search.substr(1).match(reg);
            if (r != null) return unescape(r[2]); return null;
        }

        $(function () {
            $.post("GetItem", { json: "PayInfo", mSystemAppID: parent.window.getSystemAppID() }, function (data) {
                var mdata = mini.decode(data);
                mini.getbyName("FPayID").setValue(mdata.FItemID);
                mini.getbyName("FPayID").setText(mdata.FNumber);
                mini.getbyName("FPayName").setValue(mdata.FName);
            });
            GetBillNo();
        });

        function GetClassID() {
            var FNumber = mini.getbyName("FNumber").getText();
            $.post("GetCorpClass", { json:"[{'FItemID':'"+ FNumber+"', 'mSystemAppID':'"+ parent.window.getSystemAppID()+"'}]" }, function (data) {
                var mdata = mini.decode(data);
                if (mdata.data.length > 0) {
                    mini.getbyName("FNumber").setValue(mdata.data[0].FItemID);
                    mini.getbyName("FName").setValue(mdata.data[0].FName);
                    mini.getbyName("FRemark").setValue('');
                    mini.getbyName("FCurrentAmount").setValue(mdata.data[0].FAmount);
                    mini.getbyName("FPoint").setValue(0);
                    mini.getbyName("BillNo").setValue(mdata.BillOrder[0].FBillNo);
                    mini.getbyName("BillID").setValue(mdata.BillOrder[0].FEntryID);
                }
            });
        }

        function NewInfo() {
            mini.getbyName("FNumber").setText('');
            mini.getbyName("FName").setValue('');
            mini.getbyName("FRemark").setValue('');
            mini.getbyName("FAmount").setValue(0);
            mini.getbyName("FPoint").setValue(0);
        }

        function onButtonEdit() {
            mini.open({
                url: "../GetItem/index",
                title: "服务商选择", width: 730, height: 460,
                onload: function () {
                    var iframe = this.getIFrameEl();
                    var data = { action: "new", sTbName: "CorpClass", sSearchKey: "" };
                    iframe.contentWindow.SetData(data);
                },
                ondestroy: function (action) {
                    if (action.length > 0) {
                        mini.getbyName("FNumber").setText(action[0].FNumber);
                        mini.getbyName("FNumber").setValue(action[0].FItemID);
                        GetClassID(action.FNumber);
                    }
                }
            });
        }

        function SaveInfo() {
            mini.getbyName("SaveInfo").disable();
            var form = new mini.Form("#form1");
            form.validate();
            if (form.isValid() == false) return;
            var data = form.getData();
            if (data.FAmount == 0 && data.FSetAmount == 0) {
                mini.showTips({ content: '未输入充值金额', state: "danger", x: "center", y: "top", timeout: 3000 });
                mini.getbyName("SaveInfo").enable();
                return;
            }
            var json = mini.encode(data);
            $.post("SaveRecharge", { json: json, mSystemAppID: parent.window.getSystemAppID() }, function (data) {
                var ret = mini.decode(data);
                if (ret.status > 0) {
                    GetBillNo();
                    mini.showTips({ content: ret.msg, state: "success", x: "center", y: "top", timeout: 3000 });
                    NewInfo();
                }
                else {
                    mini.alert("出现错误，错误信息:" + ret.error);
                }
                mini.getbyName("SaveInfo").enable();
                NewInfo();
            });
        }

        function GetBillNo() {
            var Json = '[{"type":"' + mini.getbyName("Type").getValue() + '","mSystemAppID":"' + parent.window.getSystemAppID() + '"}]';
            $.post("GetRechargeBillNo", { json: Json }, function (data) {
                mini.getbyName("BillNo").setValue(data);
            });

        }

        function FormShown() { mini.parse();}
</script>


